package cn.lijiajia3515.cairo.system.modules.imgproxy;

import cn.lijiajia3515.cairo.system.framework.imgproxy.ImgProxy;
import cn.lijiajia3515.cairo.system.framework.imgproxy.ImgProxyProperties;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class ImgproxyService {
	final byte[] KEY;
	final byte[] SLAT;

	private final ImgProxyProperties properties;

	public ImgproxyService(ImgProxyProperties properties) {

		this.properties = properties;
		KEY = ImgProxy.hexStringToByteArray(properties.getKey());
		SLAT = ImgProxy.hexStringToByteArray(properties.getSlat());
	}

	public String getSingedUri(String url, Map<String, String> params) throws Exception {
		return ImgProxy.generateSignedUrl(KEY, SLAT, url, params);
	}


	public String getSingedUrl(String url, Map<String, String> params) throws Exception {
		return properties.getServer() + ImgProxy.generateSignedUrl(KEY, SLAT, url, params);
	}
}
